-
-
Notifications
You must be signed in to change notification settings - Fork 321
fix(notifications): clean up control flow and fix PR/Issue action confirmations #744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(notifications): clean up control flow and fix PR/Issue action confirmations #744
Conversation
…firmations - Refactor NotificationsView key handling for clearer control flow: - Check for PR/Issue actions first, then handle navigation - Always return after updating prView/issueSidebar (fixes tab navigation) - Remove redundant MarkAsRead handler (section handles it) - Fix PR/Issue action confirmations in Notifications view: - Add promptConfirmationForNotificationPR/Issue methods - Use footer-based confirmation instead of section confirmation - Add executeNotificationAction to run tasks after confirmation - Add closeIssue/reopenIssue helper methods
9ff588b to
d8ccb5c
Compare
| if m.pendingNotificationAction != "" { | ||
| if msg.String() == "y" || msg.String() == "Y" || msg.Type == tea.KeyEnter { | ||
| cmd = m.executeNotificationAction() | ||
| } | ||
| // Any other key cancels the confirmation | ||
| m.pendingNotificationAction = "" | ||
| m.footer.SetLeftSection("") | ||
| return m, cmd | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering, what's preventing the notificationsview from handling
confirmation the same as the other views? e.g. in https://github.com/dlvhdr/gh-dash/blob/main/internal/tui/components/prview/prview.go?plain=1#L100
| var prCmd tea.Cmd | ||
| m.prView, prCmd = m.prView.Update(msg) | ||
| m.syncSidebar() | ||
| return m, prCmd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to use use cmds = append(cmds, prCmd) instead of return m, prCmd
since the scrolling happens in the sidebar component which gets updated here. Right now scrolling in the sidebar with Ctrl+D etc doesn't work.
| } | ||
| // Sync sidebar and return issueCmd for navigation | ||
| m.syncSidebar() | ||
| return m, issueCmd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
|
|
||
| // Create a section identifier for the notification section | ||
| currSection := m.getCurrSection() | ||
| sid := tasks.SectionIdentifier{Id: 0, Type: notificationssection.SectionType} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use m.currSectionId
| switch action { | ||
| case "pr_close": | ||
| if pr := m.notificationView.GetSubjectPR(); pr != nil { | ||
| return tasks.ClosePR(m.ctx, sid, pr) | ||
| } | ||
| case "pr_reopen": | ||
| if pr := m.notificationView.GetSubjectPR(); pr != nil { | ||
| return tasks.ReopenPR(m.ctx, sid, pr) | ||
| } | ||
| case "pr_ready": | ||
| if pr := m.notificationView.GetSubjectPR(); pr != nil { | ||
| return tasks.PRReady(m.ctx, sid, pr) | ||
| } | ||
| case "pr_merge": | ||
| if pr := m.notificationView.GetSubjectPR(); pr != nil { | ||
| return tasks.MergePR(m.ctx, sid, pr) | ||
| } | ||
| case "pr_update": | ||
| if pr := m.notificationView.GetSubjectPR(); pr != nil { | ||
| return tasks.UpdatePR(m.ctx, sid, pr) | ||
| } | ||
| case "issue_close": | ||
| if issue := m.notificationView.GetSubjectIssue(); issue != nil { | ||
| return m.closeIssue(sid, issue) | ||
| } | ||
| case "issue_reopen": | ||
| if issue := m.notificationView.GetSubjectIssue(); issue != nil { | ||
| return m.reopenIssue(sid, issue) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| switch action { | |
| case "pr_close": | |
| if pr := m.notificationView.GetSubjectPR(); pr != nil { | |
| return tasks.ClosePR(m.ctx, sid, pr) | |
| } | |
| case "pr_reopen": | |
| if pr := m.notificationView.GetSubjectPR(); pr != nil { | |
| return tasks.ReopenPR(m.ctx, sid, pr) | |
| } | |
| case "pr_ready": | |
| if pr := m.notificationView.GetSubjectPR(); pr != nil { | |
| return tasks.PRReady(m.ctx, sid, pr) | |
| } | |
| case "pr_merge": | |
| if pr := m.notificationView.GetSubjectPR(); pr != nil { | |
| return tasks.MergePR(m.ctx, sid, pr) | |
| } | |
| case "pr_update": | |
| if pr := m.notificationView.GetSubjectPR(); pr != nil { | |
| return tasks.UpdatePR(m.ctx, sid, pr) | |
| } | |
| case "issue_close": | |
| if issue := m.notificationView.GetSubjectIssue(); issue != nil { | |
| return m.closeIssue(sid, issue) | |
| } | |
| case "issue_reopen": | |
| if issue := m.notificationView.GetSubjectIssue(); issue != nil { | |
| return m.reopenIssue(sid, issue) | |
| } | |
| } | |
| pr := m.notificationView.GetSubjectPR() | |
| issue := m.notificationView.GetSubjectIssue(); | |
| switch action { | |
| case "pr_close": | |
| if pr != nil { | |
| return tasks.ClosePR(m.ctx, sid, pr) | |
| } | |
| case "pr_reopen": | |
| if pr != nil { | |
| return tasks.ReopenPR(m.ctx, sid, pr) | |
| } | |
| case "pr_ready": | |
| if pr != nil { | |
| return tasks.PRReady(m.ctx, sid, pr) | |
| } | |
| case "pr_merge": | |
| if pr != nil { | |
| return tasks.MergePR(m.ctx, sid, pr) | |
| } | |
| case "pr_update": | |
| if pr != nil { | |
| return tasks.UpdatePR(m.ctx, sid, pr) | |
| } | |
| case "issue_close": | |
| if issue != nil { | |
| return m.closeIssue(sid, issue) | |
| } | |
| case "issue_reopen": | |
| if issue != nil { | |
| return m.reopenIssue(sid, issue) | |
| } | |
| } |
| } | ||
|
|
||
| // closeIssue executes the close action for an Issue using gh CLI | ||
| func (m *Model) closeIssue(sid tasks.SectionIdentifier, issue *data.IssueData) tea.Cmd { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | ||
|
|
||
| // reopenIssue executes the reopen action for an Issue using gh CLI | ||
| func (m *Model) reopenIssue(sid tasks.SectionIdentifier, issue *data.IssueData) tea.Cmd { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // This is separate from section confirmation because PR/Issue actions in | ||
| // notification view need to be executed on the notification's subject PR/Issue, | ||
| // not on the notification section itself. | ||
| pendingNotificationAction string // "pr_close", "pr_merge", "issue_close", etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this live in the notificationsview? well if we move some logic there it
makes sense
Summary
Refactor
NotificationsViewkey handling for clearer control flow:prView/issueSidebar(fixes tab navigation)MarkAsReadhandler (section handles it)Fix PR/Issue action confirmations in Notifications view:
promptConfirmationForNotificationPR/IssuemethodsexecuteNotificationActionto run tasks after confirmationcloseIssue/reopenIssuehelper methodsHow did you test this change?
Tests included!